<?php

namespace app\models;

use Yii;
use yii\data\Pagination;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "tb_filecomment".
 *
 * @property integer $id
 * @property integer $fileid
 * @property string $username
 * @property string $content
 * @property string $datetime
 * @property TbArticle $file
 */
class TbFilecomment extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tb_filecomment';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['fileid'], 'integer'],
            [['content'], 'string'],
            [['datetime'], 'safe'],
            [['username'], 'string', 'max' => 20],
            [['fileid'], 'exist', 'skipOnError' => true, 'targetClass' => TbArticle::className(), 'targetAttribute' => ['fileid' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'fileid' => Yii::t('app', 'Fileid'),
            'username' => Yii::t('app', 'Username'),
            'content' => Yii::t('app', 'Content'),
            'datetime' => Yii::t('app', 'Datetime'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getFile()
    {
        return $this->hasOne(TbArticle::className(), ['id' => 'fileid']);
    }

    /**
     * 根据id查找评论以评论时间显示
     */
    public static function selectidtime($id){
        return $public = TbFilecomment::find()->where(['fileid'=>$id])->orderBy('datetime desc')->all();
    }
}